﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shuriken.Base;

namespace iTunes
{
    [ActionName("Next Song")]
    [ActionSubjectType(typeof(IApplicationItem))]
    public class NextSongAction : BaseAction
    {
        public override bool CanExecuteOn(ISubject subject)
        {
            if (subject is IApplicationItem && subject.Name.Equals("iTunes"))
            {
                return true;
            }

            return false; 
        }

        public override void Execute(ISubject subject)
        {
            throw new NotImplementedException();
        }
    }

    [ActionName("Previous Song")]
    [ActionSubjectType(typeof(IApplicationItem))]
    public class PreviousSongAction : BaseAction
    {
        public override bool CanExecuteOn(ISubject subject)
        {
            if (subject is IApplicationItem && subject.Name.Equals("iTunes"))
            {
                return true;
            }

            return false; 
        }

        public override void Execute(ISubject subject)
        {
            throw new NotImplementedException();
        }
    }

    [ActionName("Play/Pause")]
    [ActionSubjectType(typeof(IApplicationItem))]
    public class PlayPauseAction : BaseAction
    {
        public override bool CanExecuteOn(ISubject subject)
        {
            if (subject is IApplicationItem && subject.Name.Equals("iTunes"))
            {
                return true;
            }

            return false; 
        }

        public override void Execute(ISubject subject)
        {
            throw new NotImplementedException();
        }
    }

    [ActionName("Volume Down")]
    [ActionSubjectType(typeof(IApplicationItem))]
    public class VolumeDownAction : BaseAction
    {
        public override bool CanExecuteOn(ISubject subject)
        {
            if (subject is IApplicationItem && subject.Name.Equals("iTunes"))
            {
                return true;
            }

            return false; 
        }

        public override void Execute(ISubject subject)
        {
            throw new NotImplementedException();
        }
    }

    [ActionName("Volume Up")]
    [ActionSubjectType(typeof(IApplicationItem))]
    public class VolumeUpAction : BaseAction
    {
        public override bool CanExecuteOn(ISubject subject)
        {
            if (subject is IApplicationItem && subject.Name.Equals("iTunes"))
            {
                return true;
            }

            return false; 
        }

        public override void Execute(ISubject subject)
        {
            throw new NotImplementedException();
        }
    }

    //internal sealed class iTunesActionsImplemetation
    //    {
    //        private static ApplicationCommandHelper m_AppCommandHelper;

    //        static iTunesActionsImplemetation()
    //        {
    //            List<string> wndClasses = new List<string>();

    //            wndClasses.Add("iTunes");

    //            m_AppCommandHelper = new ApplicationCommandHelper(wndClasses);
    //        }


    //        /// <summary>
    //        /// Play Pause Command 
    //        /// </summary>
    //        internal static void PlayPauseAction()
    //        {
    //            m_AppCommandHelper.PlayPauseCommand();
    //        }

    //        /// <summary>
    //        /// Mute Volume Command 
    //        /// </summary>
    //        internal static void VolumeMuteAction()
    //        {
    //            m_AppCommandHelper.VolumeMuteCommmand();
    //        }

    //        /// <summary>
    //        /// Volume Up Command 
    //        /// </summary>
    //        internal static void VolumeUpAction()
    //        {
    //            m_AppCommandHelper.VolumeUpCommand();
    //        }

    //        /// <summary>
    //        /// Volume Down Command 
    //        /// </summary>
    //        internal static void VolumeDownAction()
    //        {
    //            m_AppCommandHelper.VolumeDownCommand();
    //        }

    //        /// <summary>
    //        /// Next Track Command 
    //        /// </summary>
    //        internal static void NextTrackAction()
    //        {
    //            m_AppCommandHelper.NextTrackCommand();
    //        }

    //        /// <summary>
    //        /// Previous Track Command 
    //        /// </summary>
    //        internal static void PreviousTrackAction()
    //        {
    //            m_AppCommandHelper.PreviousTrackCommand();
    //        }

    //    }

    //internal class ApplicationCommandHelper
    //{
    //    List<string> m_WindowClassNames;
    //    /// <summary>
    //    /// Application command helper class 
    //    /// </summary>
    //    /// <param name="WindowClass">name of the window class</param>
    //    public ApplicationCommandHelper(string WindowClassName)
    //    {
    //        m_WindowClassNames = new List<string>();
    //        m_WindowClassNames.Add(WindowClassName);
    //    }

    //    /// <summary>
    //    /// Application command helper class 
    //    /// </summary>
    //    /// <param name="WindowClasses">list of the names of the window classes</param>
    //    public ApplicationCommandHelper(List<string> WindowClassNames)
    //    {
    //        m_WindowClassNames = new List<string>();
    //        m_WindowClassNames.AddRange(WindowClassNames);
    //    }

    //    /// <summary>
    //    /// Retrieves the handle for a Window. 
    //    /// </summary>
    //    /// <returns>Window Handle</returns>
    //    private System.IntPtr GetWindowHandle()
    //    {
    //        System.IntPtr hwndWindow = System.IntPtr.Zero;

    //        foreach (string wndClass in m_WindowClassNames)
    //        {
    //            hwndWindow = Shell.ShellAPI.FindWindow(wndClass, null);

    //            if (System.IntPtr.Zero != hwndWindow) break;
    //        }

    //        return hwndWindow;
    //    }

    //    /// <summary>
    //    /// Sends an app command to the specified Window
    //    /// </summary>
    //    /// <param name="cmd">Application Command</param>
    //    public void SendAppCommand(int cmd)
    //    {
    //        System.IntPtr hwndWindow = GetWindowHandle();

    //        if (System.IntPtr.Zero != hwndWindow)
    //        {
    //            Shell.ShellAPI.SendMessage(hwndWindow, Shell.ShellAPI.WM_APPCOMMAND, 0, (cmd << 16));
    //        }
    //    }

    //    /// <summary>
    //    /// Play Pause Command 
    //    /// </summary>
    //    public void PlayPauseCommand()
    //    {
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_MEDIA_PLAY_PAUSE);
    //    }

    //    /// <summary>
    //    /// Mute Volume Command 
    //    /// </summary>
    //    public void VolumeMuteCommmand()
    //    {
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_VOLUME_MUTE);
    //    }

    //    /// <summary>
    //    /// Volume Up Command 
    //    /// </summary>
    //    public void VolumeUpCommand()
    //    {
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_VOLUME_UP);
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_VOLUME_UP);
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_VOLUME_UP);
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_VOLUME_UP);
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_VOLUME_UP);
    //    }

    //    /// <summary>
    //    /// Volume Down Command 
    //    /// </summary>
    //    public void VolumeDownCommand()
    //    {
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_VOLUME_DOWN);
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_VOLUME_DOWN);
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_VOLUME_DOWN);
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_VOLUME_DOWN);
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_VOLUME_DOWN);
    //    }

    //    /// <summary>
    //    /// Next Track Command 
    //    /// </summary>
    //    public void NextTrackCommand()
    //    {
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_MEDIA_NEXTTRACK);
    //    }

    //    /// <summary>
    //    /// Previous Track Command 
    //    /// </summary>
    //    public void PreviousTrackCommand()
    //    {
    //        SendAppCommand(Shell.ShellAPI.APPCOMMAND_MEDIA_PREVIOUSTRACK);
    //    }

    //}
}
